﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace BBBot
{
    public partial class ConnectingForm : Form
    {
        public ConnectingForm()
        {
            InitializeComponent();
        }

        private void ConnectingForm_Activated(object sender, EventArgs e)
        {
           Program.Client.Connect(Program.AppConfig.Host, int.Parse(Program.AppConfig.Port));
           Program.Client.StatusChanged += new EventHandler<Lidgren.Library.Network.NetStatusEventArgs>(Client_StatusChanged);            
        }

        void Client_StatusChanged(object sender, Lidgren.Library.Network.NetStatusEventArgs e)
        {
            if (Program.Client.Status == Lidgren.Library.Network.NetConnectionStatus.Connected)
            {
                DialogResult = DialogResult.OK;
            }
            if (Program.Client.Status == Lidgren.Library.Network.NetConnectionStatus.Disconnected && DialogResult != DialogResult.Cancel)
            {
                // Retry connexion
                Program.Client.Connect(Program.AppConfig.Host, int.Parse(Program.AppConfig.Port));
            }
        }
    }
}
